/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javamail.sdp.util;

/**
 *
 * @author sriram
 */
public enum eSdpMediaType {
    NIL(0, ""),
    AUDIO(1, "audio"), 
    VIDEO(2,"video"), 
    TEXT(3, "text"), 
    APPLICATION(4, "application"), 
    MESSAGE(5, "message");
    // NOT USED anymore as per RFC4566 8.2.1. Media Types ("media")
    //CONTROL(6, "control"),
    //DATA(7, "data");
    
    private final int index;
    private final String str;
    
    eSdpMediaType(int index, String string) {
        this.index = index;
        this.str = string;
    }
    
    public int toInt() {
        return index;
    }
 
    @Override
    public String toString() {
        return str;
    }
    
    public static eSdpMediaType fromString(String mediaType) {
        if(mediaType == null)
            return NIL;
        //Convert to Lower case and trim the string
        mediaType = mediaType.toLowerCase().trim();
        for (eSdpMediaType head : eSdpMediaType.values()) {
            if(mediaType.equals(head.toString().trim().toLowerCase()))
                return head;
        }
        return NIL;
    }
}
